﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BUS;

namespace TuyenDungViecLam.User_control_VN
{
    public partial class List_Job : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                dlnhatuyendung.DataSource = NhaTuyenDung_BUS.DanhSachNhaTuyenDung();
                dlnhatuyendung.DataTextField = "Ten";
                dlnhatuyendung.DataValueField = "MaNhaTuyenDung";
                dlnhatuyendung.DataBind();
                LienKetDuLieu();
            }
        }

        private void LienKetDuLieu()
        {
            dscongviec.DataSource = ChiTietCongViec_BUS.DanhSachCacCongViecThuocNhaTuyenDung(dlnhatuyendung.SelectedValue.ToString());
            dscongviec.DataBind();
        }



        //protected void dscongviec_RowCommand(object sender, GridViewCommandEventArgs e)
        //{
        //    if (e.CommandName == "Edit")
        //    {
        //        string url = "SuaTinTuyenDung.aspx?Mcv=" + e.CommandArgument.ToString() + "&Mct=" + Request.QueryString["Mct"] + "&Edit=1";
        //        Response.Redirect(url);
        //    }
        //    if (e.CommandName == "Delete")
        //    {
        //        ChiTietCongViec_BUS.HuyCongViec(e.CommandArgument.ToString());
        //        //string url = "/NhaTuyenDung/QuanLyTinTuyenDung.aspx?Mct=" + Request.QueryString["Mct"];
        //        //Response.Redirect(url);
        //        LienKetDuLieu();
        //    }
        //}

        protected void dscongviec_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            dscongviec.PageIndex = e.NewPageIndex;
            LienKetDuLieu();
        }

        protected void dscongviec_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //int n = e.RowIndex;
            //int m = dscongviec.Rows[e.RowIndex].Cells[0].Controls.Count;
            //Label ma = (Label)dscongviec.Rows[e.RowIndex].Cells[0].FindControl("lbmacongviec");
            //ChiTietCongViec_BUS.HuyCongViec(ma.Text);
            //LienKetDuLieu();
        }

        protected void dscongviec_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                string url = "SuaTin.aspx?Mcv=" + e.CommandArgument.ToString() + "&Mct=" + Request.QueryString["Mct"] + "&Edit=1";
                Response.Redirect(url);
            }
            if (e.CommandName == "Delete")
            {
                ChiTietCongViec_BUS.HuyCongViec(e.CommandArgument.ToString());
                //string url = "/NhaTuyenDung/QuanLyTinTuyenDung.aspx?Mct=" + Request.QueryString["Mct"];
                //Response.Redirect(url);
                LienKetDuLieu();
            }
        }


        protected void dlnhatuyendung_SelectedIndexChanged1(object sender, EventArgs e)
        {
            LienKetDuLieu();
        }
    }
}